/**
    入驻小区
**/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            storeIntegralInfo: {
                integrals: [],
                total: 0,
                records: 1,
                moreCondition: false,
                integralId: '',
                conditions: {
                    integralName: '',
                    objType: '7007',
                    objId: '',
                    amount: '',
                }
            }
        },
        _initMethod: function () {
            $that._listIntegrals(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {

            vc.on('storeIntegral', 'listIntegral', function (_param) {
                $that._listIntegrals(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listIntegrals(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listIntegrals: function (_page, _rows) {
                $that.storeIntegralInfo.conditions.page = _page;
                $that.storeIntegralInfo.conditions.row = _rows;
                let param = {
                    params: $that.storeIntegralInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/integral.listIntegral',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.storeIntegralInfo.total = _json.total;
                        $that.storeIntegralInfo.records = _json.records;
                        $that.storeIntegralInfo.integrals = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.storeIntegralInfo.records,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openDeleteIntegralModel: function (_integral) {
                vc.emit('deleteIntegral', 'openDeleteIntegralModal', _integral);
            },
            _queryIntegralMethod: function () {
                $that._listIntegrals(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _changeIntegralAmount:function(_integral,_detailType){
                vc.emit('editIntegral', 'openEditIntegralModal',{
                    detailType:_detailType,
                    integralName:_integral.integralName,
                    integralId:_integral.integralId,
                    amount:_integral.amount,
                    link:_integral.link
                });
            },
            _moreCondition: function () {
                if ($that.storeIntegralInfo.moreCondition) {
                    $that.storeIntegralInfo.moreCondition = false;
                } else {
                    $that.storeIntegralInfo.moreCondition = true;
                }
            }
        }
    });
})(window.vc);
